<?php
/**
 * Created by JetBrains NetBeans.
 * User: yinyancai
 * Date: 13-3-14 下午4:44
 * To change this template use File | Settings | File Templates.
 */
if (!defined('IN_MOBILE_API')) {
    exit('Access Denied');
}
include_once 'forum.php';
class cloud_api {
    function common() { }

    function output() {
        //判断是否缺少参数
        if (empty($_GET['cpid']) || empty($_GET['cuid']) || empty($_GET['grade']) || empty($_GET['messages'])) {
            $variable = array(
                'code' => 1001,
                'messagestr' => lang('plugin/cloud', '1001'),
            );
            cloud_core::result(cloud_core::variable($variable));
        }
        $cadid=$_GET['cadid'];
        if(empty($cadid)){
            $data_product = C::t('#cloud#cloud_product')->fetch_info($_GET['cpid']);
            $cadid = $data_product['cadid'];
        }
        $users = C::t('#cloud#cloud_users')->fetch_info($_GET['cuid']);
        //新增
        $data = array(
            'cpid' => $_GET['cpid'],
            'cuid' => $_GET['cuid'],
            'coid' => $_GET['coid'],
            'cadid' =>$cadid,
            'cuname' => $users['name'],
            'messages' => $_GET['messages'],
            'supportnum' => $_GET['supportnum'],
            'grade' => $_GET['grade'],
             'lasttime' => TIMESTAMP,
        );
        $caid = C::t('#cloud#cloud_product_assess')->insert($data);
        //如果插入失败，这返回错误信息
        if (empty($caid)) {
            $variable = array(
                'code' => 11009,
                'messagestr' => lang('plugin/cloud', '11009'),
            );
            cloud_core::result(cloud_core::variable($variable));
        }

        $product = C::t('#cloud#cloud_product')->fetch_info($_GET['cpid']);

        $assessnum = intval($product['assessnum']) + 1;
        $marketnum = intval($product['marketnum']) + 1;
        $gradeCount = intval($product['gradeCount']) + intval($_GET['grade']);
        $grade = round(intval($gradeCount) / intval($assessnum));

        $updateProduct = array(
            'assessnum' => $assessnum,
            'gradeCount' => $gradeCount,
            'grade' => $grade,
            'marketnum' => $marketnum,
        );
        C::t('#cloud#cloud_product')->update($product['cpid'], $updateProduct);
        //正常返回
        $variable = array(
            'messagestr' => lang('plugin/cloud', '11010'),
        );
        cloud_core::result(cloud_core::variable($variable));
    }
}

?>

